#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QToolBar>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QMenuBar* menuBar=this->menuBar();
    this->setMenuBar(menuBar);

    QMenu* menu=new QMenu("菜单");
    menuBar->addMenu(menu);


    //工具栏需要手动创建，自身不会被创建、
    QToolBar* toolBar=new QToolBar();
    this->addToolBar(toolBar);

    QAction* action1=new QAction("保存");
    QAction* action2=new QAction("打开");
    //菜单项放到菜单中
    menu->addAction(action1);
    menu->addAction(action2);

    //菜单项放到工具栏中
    toolBar->addAction(action1);
    toolBar->addAction(action2);

    action1->setToolTip("保存文件");
    action2->setToolTip("打开文件");

    action1->setIcon(QIcon(":/save.png"));
    action2->setIcon(QIcon(":/file.png"));



    connect(action1,&QAction::triggered,this,&MainWindow::handle1);

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle1()
{
    qDebug()<<"handle1()";
}
